package com.eleventwelve.iris.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.eleventwelve.iris.entity.Patient;
import com.eleventwelve.iris.entity.PatientMedicalProgram;
import com.eleventwelve.iris.service.PatientMedicalProgramService;
import com.eleventwelve.iris.service.PatientService;

public class DeletePatientMedicalProgramController extends AbstractController{
	private PatientMedicalProgramService patientMedicalProgramService;
	private PatientService patientService;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		Patient patient = null; 
		if(!StringUtil.isEmpty(id) && StringUtils.isNumeric(id)){
			PatientMedicalProgram patientMedicalProgram = patientMedicalProgramService.load(id);
			patient = patientMedicalProgram.getPatient();
			patientMedicalProgramService.delete(patientMedicalProgram.getId());
			
		}
		
		return new ModelAndView("redirect:/patient.jspx?action=delete&item=Program&id="+patient.getId());
	}

	public PatientMedicalProgramService getPatientMedicalProgramService() {
		return patientMedicalProgramService;
	}

	public void setPatientMedicalProgramService(
			PatientMedicalProgramService patientMedicalProgramService) {
		this.patientMedicalProgramService = patientMedicalProgramService;
	}

	public PatientService getPatientService() {
		return patientService;
	}

	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}

}
